import { fetchApi, request, type PaginationParams } from ".";
import type { Report } from "@/stores/types";

export interface CreateReportData {
  courseId: number;
  serial: number;
  name: string;
  objectives: string;
  equipment: string;
  content: string;
  result: string;
  date: string;
}

/**
 * 创建报告
 * @param params 报告参数
 * @returns ApiResponse<Report>
 */
export function createReport(params: CreateReportData) {
  return fetchApi<Report>("/report", {
    method: "POST",
    body: JSON.stringify(params),
  });
}

/**
 * 更新报告
 * @param id 报告ID
 * @param params 报告参数
 * @returns ApiResponse<Report>
 */
export function updateReport(id: number, params: CreateReportData) {
  return fetchApi<Report>(`/report/${id}`, {
    method: "PUT",
    body: JSON.stringify(params),
  });
}

export function findCourseReports(courseId: number, params: PaginationParams) {
  return fetchApi<Report>(`/course/${courseId}/reports`, {
    method: "GET",
    params,
  });
}

export function deleteReport(id: number) {
  return fetchApi<Report>(`/report/${id}`, {
    method: "DELETE",
  });
}

export function exportReport(id: number) {
  return request.raw<Blob>(`/report/export/${id}`, {
    method: "GET",
    responseType: "blob",
  });
}
